package com.kedou.sdk.params.bean;

import android.os.Parcel;
import android.os.Parcelable;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2018/2/7.
 */

public class RealNameInfo implements Parcelable {

    private boolean userAdultState = false;

    private boolean configAdultState = false;

    private boolean needRealNameCertifiesBeforePayment = false;

    private boolean realNameCertified = false;

    public RealNameInfo(){}

    public boolean isOpen() {
        return configAdultState && (!userAdultState);
    }

    /**
     * 平台防沉迷开启状态设置
     * @param configAdultState
     */
    public void setConfigAdultState(boolean configAdultState) {
        this.configAdultState = configAdultState;
    }

    /**
     * 用户是否成年状态设置
     * @param userAdultState
     */
    public void setUserAdultState(boolean userAdultState) {
        this.userAdultState = userAdultState;
    }

    public boolean isNeedRealNameCertifiesBeforePayment() {
        return needRealNameCertifiesBeforePayment && !realNameCertified;
    }

    /**
     * 支付之前是否需要提示用户进行实名认证
     * @param needRealNameCertifiesBeforePayment
     */
    public void setNeedRealNameCertifiesBeforePayment(boolean needRealNameCertifiesBeforePayment) {
        this.needRealNameCertifiesBeforePayment = needRealNameCertifiesBeforePayment;
    }


    public boolean isRealNameCertified() {
        return realNameCertified;
    }

    /**
     * 设置是否有进行实名认证操作/身份证绑定操作
     * @param realNameCertified true表示已经实名认证，false表示没有
     */
    public void setRealNameCertified(boolean realNameCertified) {
        this.realNameCertified = realNameCertified;
    }

    @Override
    public String toString() {
        JSONObject json = new JSONObject();
        try {
            json.put("isOpen", isOpen());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return json.toString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(this.userAdultState ? (byte) 1 : (byte) 0);
        dest.writeByte(this.configAdultState ? (byte) 1 : (byte) 0);
        dest.writeByte(this.needRealNameCertifiesBeforePayment ? (byte) 1 : (byte) 0);
        dest.writeByte(this.realNameCertified ? (byte) 1 : (byte) 0);
    }

    protected RealNameInfo(Parcel in) {
        this.userAdultState = in.readByte() != 0;
        this.configAdultState = in.readByte() != 0;
        this.needRealNameCertifiesBeforePayment = in.readByte() != 0;
        this.realNameCertified = in.readByte() != 0;
    }

    public static final Creator<RealNameInfo> CREATOR = new Creator<RealNameInfo>() {
        @Override
        public RealNameInfo createFromParcel(Parcel source) {
            return new RealNameInfo(source);
        }

        @Override
        public RealNameInfo[] newArray(int size) {
            return new RealNameInfo[size];
        }
    };
}
